package pwd.allen.service.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;
import pwd.allen.service.IHelloService;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 *
 * 将服务提供者注册到注册中心（暴露服务）
 *      1）、导入dubbo依赖和操作zookeeper的客户端
 *      2）、配置服务提供者
 *
 * @author 门那粒沙
 * @create 2019-10-03 17:04
 **/
@DubboService(version = "pwd-1.0", methods = @Method(name = "sayHello", timeout = 10000))
public class HelloServiceImpl implements IHelloService {

    @Value("${dubbo.protocol.port:0}")
    private int port;

    @Override
    public String sayHello(String name) {
        try {
            TimeUnit.SECONDS.sleep(1);
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello!" + name + "! dubbo.protocol.port=" + port;
    }

    @Override
    public Map getMap(Map<String, Object> map) {
        return Collections.singletonMap("port", port);
    }

}
